/*
*  Copyright 2019-2020 Liu
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package com.liu.modules.business.rest;


import com.liu.annotation.AnonymousAccess;
import com.liu.modules.business.domain.EjlAcessNovelLog;
import com.liu.modules.business.service.EjlAcessNovelLogService;
import com.liu.modules.business.service.dto.EjlAcessNovelLogQueryCriteria;
import com.liu.annotation.Log;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

/**
* @website https://el-admin.vip
* @author Liu
* @date 2022-07-08
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "用户浏览记录管理管理")
@RequestMapping("/api/ejlAcessNovelLog")
public class EjlAcessNovelLogController {

    private final EjlAcessNovelLogService ejlAcessNovelLogService;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('ejlAcessNovelLog:list')")
    public void download(HttpServletResponse response, EjlAcessNovelLogQueryCriteria criteria) throws IOException {
        ejlAcessNovelLogService.download(ejlAcessNovelLogService.queryAll(criteria), response);
    }

    @GetMapping
    @Log("查询用户浏览记录管理")
    @ApiOperation("查询用户浏览记录管理")
    @AnonymousAccess
    public ResponseEntity<Object> query(EjlAcessNovelLogQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(ejlAcessNovelLogService.queryAll(criteria,pageable),HttpStatus.OK);
    }


    @Log("查询小说推荐排行")
    @GetMapping(value = "/getNovelRecommend")
    @AnonymousAccess
    public ResponseEntity<Object> getNovelRecommend(EjlAcessNovelLogQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(ejlAcessNovelLogService.queryRecommend(criteria,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增用户浏览记录管理")
    @ApiOperation("新增用户浏览记录管理")
    @AnonymousAccess
    public ResponseEntity<Object> create(@Validated @RequestBody EjlAcessNovelLog resources){
        return new ResponseEntity<>(ejlAcessNovelLogService.create(resources),HttpStatus.CREATED);
    }



    @Log("批量新增用户浏览记录管理")
    @PostMapping(value="/batchAdd")
    @AnonymousAccess
    public ResponseEntity<Object> create(@Validated @RequestBody List<EjlAcessNovelLog> resourcesList){
        for (EjlAcessNovelLog ejlAcessNovelLog : resourcesList) {
            ejlAcessNovelLogService.create(ejlAcessNovelLog);
        }
        return new ResponseEntity<>(HttpStatus.CREATED);
    }


    @PutMapping
    @Log("修改用户浏览记录管理")
    @ApiOperation("修改用户浏览记录管理")
    @PreAuthorize("@el.check('ejlAcessNovelLog:edit')")
    public ResponseEntity<Object> update(@Validated @RequestBody EjlAcessNovelLog resources){
        ejlAcessNovelLogService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @Log("删除用户浏览记录管理")
    @ApiOperation("删除用户浏览记录管理")
    @PreAuthorize("@el.check('ejlAcessNovelLog:del')")
    @DeleteMapping
    public ResponseEntity<Object> delete(@RequestBody String[] ids) {
        ejlAcessNovelLogService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }


}